Repository navigation
サブサイトに存在しない URL を、メインサイトの同じ URL へリダイレクトしない問題を修正 - #4656
Merged
Merged
Conversation
BcRedirectMainSiteMiddleware がミドルウェアに登録されておらず、 またコンテンツの有無を判定せずにサブサイトの URL をすべてリダイレクトする実装だったため、 4系の BcRedirectMainSiteFilter と同じ判定に揃えて登録する Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The redirect drops the original query string, so requests such as /en/news/?page=2 lose pagination state and display the first page instead of the requested page.
1 open issue
転送時に元のクエリパラメーターを引き継ぐ · New
What changed in this PR
サブサイトに存在しない URL へのアクセスを、メインサイトの対応する URL へ転送する機能を修正する PR です。
変更内容:
- 対象の 404 例外を受けた場合に、サブサイトとメインサイトのルーティング可否を確認して 302 リダイレクトするよう変更。
- ミドルウェアを
RoutingMiddlewareの直前に登録。 - リダイレクト条件とミドルウェアの登録位置を確認するテストを更新。
| File | Description |
|---|---|
plugins/baser-core/tests/TestCase/Middleware/BcRedirectMainSiteMiddlewareTest.php |
転送する場合・しない場合の4ケースを検証。 |
plugins/baser-core/tests/TestCase/BaserCorePluginTest.php |
ミドルウェアの件数と登録位置を確認。 |
plugins/baser-core/src/Middleware/BcRedirectMainSiteMiddleware.php |
404 時の転送条件と転送先の安全性チェックを実装。 |
plugins/baser-core/src/BaserCorePlugin.php |
メインサイト転送用ミドルウェアを登録。 |
Review effort: Balanced
| return $response->withLocation($request->getAttribute('base') . $mainSiteUrl); | ||
| if (!$this->isRoutable($request->withUri($request->getUri()->withPath($mainSiteUrl)))) return null; | ||
| return (new Response(['status' => 302])) | ||
| ->withLocation($request->getAttribute('base') . $mainSiteUrl); |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

概要
サブサイトにコンテンツが存在しない URL にアクセスしたとき、メインサイトの同じ URL にコンテンツがあればメインサイトへリダイレクトする機能(4系の
BcRedirectMainSiteFilter)が動作していない問題を修正します。再現手順
enのサブサイトを作り、メインサイトにだけ/aboutの固定ページを作る/en/aboutにアクセスする/aboutへ 302 でリダイレクトされるが、5系では 404 になる原因
BcRedirectMainSiteMiddlewareがミドルウェアに登録されていない修正
BcRedirectMainSiteMiddlewareを 4系の判定に揃えて作り直したNotFoundException・MissingRouteException・MissingControllerException)になった場合だけ判定する//example.com等)にならないようにしたBaserCorePlugin::middleware()で、RoutingMiddlewareの直前に登録した(ルーティングで発生する例外も受け取るため)テスト
BcRedirectMainSiteMiddlewareTestを新しい仕様で書き直した(リダイレクトする/メインサイトにも無い/サブサイトにコンテンツがある/404 にならない の 4 ケース)BaserCorePluginTest::testMiddlewareで登録位置を確認plugins/baser-core/tests/TestCase/Middleware・PagesControllerTest・BcErrorControllerTest・BlogControllerTestが通ることを確認🤖 Generated with Claude Code